<script>
function myform_submit() {
    if($("#mtTypeId").val()==''){
        alert('请选择维修类型');
        return false;
    }
	if(!isempty('maintain_id','请选择维修站点生成维修单号'))return false;
	if(!isempty('consumer_name','客户姓名不能为空'))return false;
	if(!isempty('consumer_phone','客户电话不能为空'))return false;
    //邮箱验证
    if(!isempty('consumer_email','邮箱不能为空'))return false;
    var email = $("input[name=consumer_email]").val();
    var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (!reg.test(email)) {
        alert('邮箱格式不正确');
        $("input[name=email]").focus();
        return false;
    }
    //快递验证
    if($('#shfsId').val()==1){
        if(!isempty('delivery_street_address','客户街道不能为空')){
            $("input[name=delivery_street_address]").focus();
            $("input[name=freight_price]").val(0);
            return false;
        }
        if(!isempty('delivery_city','客户城市不能为空')){
            $("input[name=delivery_city]").focus();
            $("input[name=freight_price]").val(0);
            return false;
        }
        if(!isempty('delivery_state','客户州不能为空')){
            $("input[name=delivery_state]").focus();
            $("input[name=freight_price]").val(0);
            return false;
        }
        if(!isempty('delivery_country','客户国家不能为空')){
            $("input[name=delivery_country]").focus();
            $("input[name=freight_price]").val(0);
            return false;
        }
        if(!isempty('delivery_zipcode','客户邮编不能为空')){
            $("input[name=delivery_zipcode]").focus();
            $("input[name=freight_price]").val(0);
            return false;
        }
    }

    //运费验证
    if(!isempty('freight_price','运费不能为空'))return false;

    /*if($('#statusId').val()==10){
        $('input[name=track_num]').focus();
        if(!isempty('track_num','请输入追踪号'))return false;
    }*/

    //没有添加配件
    var bool_pj = true;
    if($('#statusId').val()==4){
        $.ajax('<?=blang_url('orders/order/verifyIsMaterial')?>',
            {
                type:'post',
                async: false,
                data: {'id': $("input[name=maintain_id]").val()},
                dataType:'json',
                success:function(data){
                    if(!data.success){
                        bool_pj = confirm(data.message);
                    }
                }
            }
        );
    }
    return bool_pj;
}

//生成运费
function showFreight(shfsid){
    if(!shfsid){
        $("input[name=freight_price]").val(0);
    }
    var siteId = $('#repairSiteId').val();
    var is_pickup = $("input[name='door_to_door_pickup']:checked").val();
    if(siteId ==1){
        if(shfsid==1 && is_pickup==1){
            $("input[name=freight_price]").val(8);
        }else if(shfsid==1 || is_pickup==1){
            $("input[name=freight_price]").val(4);
        }
    }else if(siteId==3 && shfsid==1){
        $("input[name=freight_price]").val(5);
    }else{
        $("input[name=freight_price]").val(0);
    }
}


//生成维修单号
function create_RepairId(mtid){
    if(6==mtid){
        $('#mtTypeId option[value=6]').prop('selected',true);
        $('#mtTypeId option').not(':selected').prop('disabled',true);
        $("input[name=freight_price]").val(0);
        $("input[name=consumer_name]").val('iphone');
        $("input[name=consumer_phone]").val('iphone');
        $("input[name=consumer_email]").val('iphone@qq.com');
    }else{
        $('#mtTypeId option').prop('disabled',false);
    }
	$.post('<?=blang_url('orders/order/get_mtSite_id')?>',{'id':mtid},function(data){
		$("input[name=maintain_id]").val(data.maintain_id);
        $(".freightPrice_sort_id").html(data.price_sort);
	},'json');
}

</script>

<!--top结束-->
<div class="mian">
	<div class="mian1">
		<div class="mian2">
			<!--left start-->
            <?php $this->load->view('defaults/common/left');?>
			<!--left end-->
			<!--right start-->
			<div class="right">
				<!--breadcrumb start-->
				<div class="righta"><?=$this->breadcrumb->generateHTML();?> </div>
				<!--breadcrumb end-->
				<!-- contents start -->
				<div id="contents">
					<div id="contents_container">
					<form action="<?=blang_url('orders/order/'.$post_type)?>" method="post" name="productform" onsubmit="return myform_submit()" autocomplete="off" >
						<table cellpadding="0" cellspacing="0" id="table_forms" border="1">
							<tr>
						      <td class="forms_left"><span>*</span><?=lang('order_wxzd')?>:</td>
						      <td >
						      	<select name="repair_site_id" id="repairSiteId" onchange="create_RepairId(this.value)"  <?=$post_type=='edit'?'disabled':'' ?>  >
								  	<option value="" > -- <?=lang('public_qxz')?> -- </option>
                                    <?php foreach ($repairList as $rs):?>
                                        <option value="<?=$rs['id']?>" <?=$optRepair[$rs['id']]?> ><?=$rs['site_name']?></option>
                                    <?php endforeach;?>
							   	</select>
                                <?php if($post_type=='edit'):?>
                                    <input type="hidden" name="repair_site_id" value="<?=$orderFirst['repair_site_id']?>" />
                                <?php endif;?>
							  </td>
						    </tr>
						    <tr>
						      <td class="forms_left" ><span>*</span><?=lang('order_wxdh')?>：</td>
                                <td colspan="2">
                                    <input readonly="readonly" name="maintain_id" value="<?=$orderFirst['maintain_id']?>" placeholder="<?=lang('order_xtsc')?>" style="color:#5a5a5a;" />
                                    <span><?=lang('order_dhxtsc')?></span>
                                </td>
						    </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_wxlx')?>:</td>
                                <td colspan="2">
                                    <select name="maintain_type_id" id="mtTypeId">
                                        <?php foreach ($mtTypeList as $rs):?>
                                            <option value="<?=$rs['maintain_type_id']?>" <?=$optMtType[$rs['maintain_type_id']]?> >
                                                <?=$rs['maintain_type_name']?>
                                            </option>
                                        <?php endforeach;?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('public_zt')?>:</td>
                                <td colspan="2">
                                    <select name="status_id" id="statusId">
                                        <?php foreach ($statusList as $rs):?>
                                            <option value="<?=$rs['status_id']?>" <?=$optStatus[$rs['status_id']]?> >
                                                <?=$rs['status_name']?>
                                            </option>
                                        <?php endforeach;?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khxm')?>:</td>
                                <td colspan="2"><input name="consumer_name" value="<?=$orderFirst['consumer_name']?>" /></td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khdh')?>:</td>
                                <td colspan="2"><input name="consumer_phone" value="<?=$orderFirst['consumer_phone']?>" /></td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khyx')?>:</td>
                                <td colspan="2"><input name="consumer_email" value="<?=$orderFirst['consumer_email']?>" /></td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khjd')?>:</td>
                                <td colspan="2">
                                    <input name="delivery_street_address" value="<?=$orderFirst['delivery_street_address']?>" />
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khcs')?>:</td>
                                <td colspan="2">
                                    <input name="delivery_city" value="<?=$orderFirst['delivery_city']?>" />
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khz')?>:</td>
                                <td colspan="2">
                                    <input name="delivery_state" value="<?=$orderFirst['delivery_state']?>" />
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khgj')?>:</td>
                                <td colspan="2">
                                    <select  name="delivery_country" style="width: 280px;">
                                        <option value="ES"<?=$orderFirst['delivery_country']=='ES'?'selected':''?> >ES</option>
                                        <option value="RU"<?=$orderFirst['delivery_country']=='RU'?'selected':''?> >RU</option>
                                        <option value="DE"<?=$orderFirst['delivery_country']=='DE'?'selected':''?> >DE</option>
                                        <option value="UK"<?=$orderFirst['delivery_country']=='UK'?'selected':''?> >UK</option>
                                        <option value="US"<?=$orderFirst['delivery_country']=='US'?'selected':''?> >US</option>
                                        <option value="PT"<?=$orderFirst['delivery_country']=='PT'?'selected':''?> >PT</option>
                                        <option value="IT"<?=$orderFirst['delivery_country']=='IT'?'selected':''?> >IT</option>
                                        <option value="FR"<?=$orderFirst['delivery_country']=='FR'?'selected':''?> >FR</option>
                                        <option value="BE"<?=$orderFirst['delivery_country']=='BE'?'selected':''?> >BE</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><span>*</span><?=lang('order_khyb')?>:</td>
                                <td colspan="2">
                                    <input name="delivery_zipcode" value="<?=$orderFirst['delivery_zipcode']?>" />
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('delivery_method')?>:</td>
                                <td >
                                    <input type="radio" name="delivery_service" value="0"  <?=$ckdDelivery['0']?>  /><?=lang('delivery_method_zq')?>&nbsp;&nbsp;
                                    <input type="radio" name="delivery_service" value="1"  <?=$ckdDelivery['1']?> /><?=lang('delivery_method_kd')?>
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('pickup_method')?>:</td>
                                <td >
                                    <input type="radio" name="pickup_service" value="0"  <?=$ckdPickup['0']?>  /><?=lang('pickup_method_smqj')?>&nbsp;&nbsp;
                                    <input type="radio" name="pickup_service" value="1"  <?=$ckdPickup['1']?>  /><?=lang('pickup_method_khzf')?>
                                </td>
                            </tr>

                            <tr id="ru_freight_price" >
                                <td class="forms_left" ><span>*</span><?=lang('price_yf')?>:</td>
                                <td colspan="2">
                                    <input name="freight_price" value="<?=$orderFirst['freight_price']?>" />
                                    <span class="freightPrice_sort_id"><?=$repairSiteFirst['price_sort']?></span>
                                    &nbsp;&nbsp;&nbsp; 0 ?
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('order_yhje')?>:</td>
                                <td colspan="2">
                                    <input name="coupon_money" value="<?=$orderFirst['coupon_money']?>" />
                                    <span class="freightPrice_sort_id"><?=$repairSiteFirst['price_sort']?></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('order_zjje')?>:</td>
                                <td colspan="2">
                                    <input name="append_money" value="<?=$orderFirst['append_money']?>" />
                                    <span class="freightPrice_sort_id"><?=$repairSiteFirst['price_sort']?></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('order_jjimei')?>:</td>
                                <td colspan="2"><input name="lent_imei" value="<?=$orderFirst['lent_imei']?>" /></td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('order_zzh')?>:</td>
                                <td colspan="2"><input name="track_num" value="<?=$orderFirst['track_num']?>" /></td>
                            </tr>
                            <tr>
                                <td class="forms_left" ><?=lang('order_lhzzh')?>:</td>
                                <td colspan="2"><input name="source_track_num" value="<?=$orderFirst['source_track_num']?>" /></td>
                            </tr>

						    <tr>
						      <td align="center" colspan="2" class="sub_padding_right">
                                <input name="id" type="hidden" value="<?=$orderFirst['maintain_id']?>" />
								<input type="submit" value="<?=lang('public_tj')?>" name="submits" />
						      </td>
						    </tr>
					   </table>
					</form>
				   </div>
				</div>
				<!-- contents end -->
			</div>
			<!--right end-->
            <div class="clear"></div>
		</div>
	</div>
</div>

